#include "cnninfo.h"

CnnInfo::CnnInfo() {}

bool CnnInfo::writeXML(const QXmlStreamWriter &writer){
    return true;
}

bool CnnInfo::ReadXML(QXmlStreamReader &reader){
    QXmlStreamReader::TokenType token = reader.readNext();
    while (!(reader.tokenType() == QXmlStreamReader::EndElement &&
             reader.name() == QStringLiteral("cnnInfo"))) {

        if (reader.name() == QStringLiteral("partWidth")) {
            m_nPartWidth = reader.readElementText().toInt();
        }else if (reader.name() == QStringLiteral("partHeight")) {
            m_nPartHeight = reader.readElementText().toInt();
        }else if (reader.name() == QStringLiteral("onnxModelPath")) {
            m_strONNXmodelPath = reader.readElementText().toStdString().c_str();
        }

        reader.readNext();
    }

    reader.readNext();
    reader.readNext();
    return true;
}

QJsonObject CnnInfo::toJson(){
    QJsonObject obj;
    obj["PartWidth"] = this->m_nPartWidth;
    obj["PartHeight"] = this->m_nPartHeight;
    return obj;
}

void CnnInfo::fromJson(QJsonObject obj){
    this->m_nPartWidth = obj["PartWidth"].toInt();
    this->m_nPartHeight = obj["PartHeight"].toInt();
}
